package com.javabasic.algorithm.leetcode;

import java.util.HashMap;

/**
 * @Author xiongmin
 * @Description //TODO
 * @Date 2020/7/11 22:34
 * @Version 1.0
 **/
public class ReformatDate {

    HashMap<String,Integer> map = new HashMap<>();

    public void init() {
        // "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
        map.put("Jan",1);map.put("Jul",7);
        map.put("Feb",2);map.put("Aug",8);
        map.put("Mar",3);map.put("Sep",9);
        map.put("Apr",4);map.put("Oct",10);
        map.put("May",5);map.put("Nov",11);
        map.put("Jun",6);map.put("Dec",12);
    }

    public String reformatDate(String date) {
        init();
        System.out.println(date);
        String[] split = date.split(" ");
        System.out.println(split.length);
        String year = split[2];
        String month = "" + map.get(split[1]);
        split[0] = split[0].replaceAll("[a-z]*","");
        System.out.println(split[0]);
        String day = "" + Integer.parseInt(split[0]);
        if (month.length() < 2) {
            month = "0" + month;
        }
        if (day.length() < 2) {
            day = "0" + day;
        }
        String result = year + "-" + month + "-" + day;
        return result;
    }
}
